# Contributor: stef <l0ls0fo2i@ctrlc.hu>
# Maintainer: André Klitzing <aklitzing@gmail.com>
pkgname=zstd
pkgver=1.4.5
pkgrel=0
pkgdesc="Zstandard - Fast real-time compression algorithm"
url="https://www.zstd.net"
arch="all"
license="BSD-3-Clause GPL-2.0-or-later"
checkdepends="file"
makedepends="grep"
subpackages="$pkgname-static $pkgname-libs $pkgname-dev $pkgname-doc"
source="zstd-$pkgver.tar.gz::https://github.com/facebook/zstd/archive/v$pkgver.tar.gz
	"

# secfixes:
#   1.3.8-r0:
#     - CVE-2019-11922

build() {
	unset CPPFLAGS
	local _moreflags="-O2"
	case "$CARCH" in
		# avoid memory copy hack that violates C standard
		armhf) _moreflags="$_moreflags -DMEM_FORCE_MEMORY_ACCESS=0" ;;
	esac
	make HAVE_PTHREAD=1 HAVE_ZLIB=0 HAVE_LZMA=0 HAVE_LZ4=0 MOREFLAGS="$_moreflags"
}

check() {
	case "$CARCH" in
		arm*) make check ;;
		*) make test ;;
	esac
}

package() {
	make PREFIX="/usr" DESTDIR="$pkgdir" install
}

static() {
	pkgdesc="zstd static library"
	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/*.a "$subpkgdir"/usr/lib/
}

sha512sums="b03c497c3e0590c3d384cb856e3024f144b2bfac0d805d80e68deafa612c68237f12a2d657416d476a28059e80936c79f099fc42331464b417593895ea214387  zstd-1.4.5.tar.gz"
